<style type="text/css">
.templatelist{
	margin:20px;
}
.templatelist table{
	margin-top:20px;
}
.templateaddiframe{
	display:none;
}
.templateadd{
	display:none;
}
.templateadd label{
	display:block;
	margin:10px 20px;
}
.templateadd input{
	width:230px;
}
.templateadd button{
	margin:0px 20px;
}
</style>
<script type="text/javascript">
$(document).ready(function(e) {
	dialog('.templateadd',{
		autoOpen:false,
		modal:true,
		resizable:false,
		title:'添加模板文件',
		width:400
	});
});
function deletetemplate(_this,id){
	var templatename=$(_this).parent().prev().text();
	if(!confirm('确定删除此模板文件吗？')){
		return;
	}
	$.getJSON('system/template!delete.action',{id:id},function(rs){
		if(rs.code=='1'){
			$(_this).parent().parent().remove();
		}else{
			alert(rs.msg);
		}
	});
}
function checkFile(){
	if(checkForm($('.templateadd *[name]'))){
		setTimeout(function(){
			$(window.frames["uploadtemplate"].document).ready(function(e) {
				$( ".loading" ).dialog('close');
				var rs=$(window.frames["uploadtemplate"].document).find('body').text()
				var data={};
				try{
					data= JSON.parse(rs);
				}catch(e){
					data=false;
				}
				if(data){
					if(data.code==1){
						/*alert('上传成功！')*/
						$('.templateadd').dialog('close')
						goPage('system/template.action','#main')
					}else{
						alert(data.msg);
					}
				}else{
					alert('上传失败！');
				}
			});
		},500);
		$( ".loading" ).dialog('open');
		return true;
	}else{
		return false;
	}
}
</script>
<div class="templatelist">
  <div class="actiontree">
    <button type="button" onClick="$('.templateadd').dialog('open')">上传模板</button>
  </div>
  <iframe class="templateaddiframe" src="" name="uploadtemplate"></iframe>
  <div class="templateadd">
  <form action="system/template!upload.action" target="uploadtemplate" enctype="multipart/form-data" method="post" onSubmit="checkFile()">
    <label>描述：<input name="description" regx="${check.description}" type="text" /></label>
    <label>文件：<input name="upfile" regx="${check.file}" type="file" /></label>
    <label><button type="submit">上传</button><button type="reset">重置</button></label>
  </form>
  </div>
  <table class="tablestyle1">
    <tr>
      <th>编号</th>
      <th>名称</th>
      <th>操作</th>
    </tr>
    <#list rslist.template as list>
    <tr>
      <td><a href="javascript:void(0)" onClick="goPage('system/template!detail.action?id=${list._id}','#main')">${list._id}</a></td>
      <td>${list.description}</td>
      <td class="action"><span onClick="deletetemplate(this,'${list._id}')">删除</span></td>
    </tr>
    </#list>
  </table>
  <#assign page=rslist>
  <#include "../page.html">
</div>